﻿package mortal.game.view.mount.panel
{
    import Message.DB.Tables.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import frEngine.pools.*;
    import frEngine.primitives.object2d.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.model.data.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.common.util.*;
    import mortal.game.view.playerSystem.view.*;
    import mortal.mvc.core.*;

    public class MountAvtivityWin extends Window
    {
        private var _bg:GImageBitmap;
        private var _titleTxt:GTextFiled;
        private var _levelTxt:GTextFiled;
        private var _levelName:GTextFiled;
        private var _returnValue:GTextFiled;
        private var _combat:BitmapNumberText;
        private var _propItem:BaseItem;
        protected var _rect3d:Rect3DObject;
        protected var _img2d:Img2D;
        protected var _bodyPlayer:ActionPlayer;
        protected var _mountHangEffect:EffectPlayer;
        private var _mountConfig:TMountConfig;
        private static var _instance:MountAvtivityWin;

        public function MountAvtivityWin()
        {
            if (_instance != null)
            {
                throw new Error("MountAvtivityWin 单例");
            }
            this.layer = LayerManager.windowLayer3D;
            this.setSize(352, 512);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            isForbidenDrag = true;
            this.visible = false;
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.ActivityBg_Mount, 0, 0, this));
            this._bg = UIFactory.gImageBitmap("", 0, 0, null, this.add2D);
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.CombatTxt, 193, 44, this.contentTopOf3DSprite));
            this._titleTxt = UIFactory.gTextField(Language.getString(35443), 153 + 2, 4, 70, 22, this.contentTopOf3DSprite, GlobalStyle.textFormatAnjin);
            this._levelTxt = UIFactory.gTextField(Language.getString(35444), 50, 42, 54, 20, this.contentTopOf3DSprite, GlobalStyle.textFormatBai);
            this._levelName = UIFactory.gTextField("", 98, 42, 70, 20, this.contentTopOf3DSprite, GlobalStyle.textFormatBai);
            this._returnValue = UIFactory.gTextField("", 120, 474, 140, 22, this.contentTopOf3DSprite, GlobalStyle.textFormatBai);
            this._combat = UIFactory.bitmapNumberText(193 + 50 + 6, 45 - 3, "PetGrowYellowNum.png", 18, 21, -6, this.contentTopOf3DSprite, 9);
            this._propItem = UICompomentPool.getUICompoment(BaseItem);
            this._propItem.setItemStyle(ItemStyleConst.Small, ImagesConst.FashionEquipBg, 9, 9);
            this._propItem.isShowColorBg = false;
            this._propItem.x = 257 + 16;
            this._propItem.y = 405 + 20 - 4;
            this._propItem.isDragAble = false;
            this.contentTopOf3DSprite.addChild(this._propItem);
            NetDispatcher.addCmdListener(ServerCommand.MountLevelUp, this.mountLevelUpdate);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.MountLevelUp, this.mountLevelUpdate);
            if (this._bodyPlayer)
            {
                this._rect3d.disposeObj3d(this._bodyPlayer);
                this._bodyPlayer = null;
            }
            if (this._rect3d)
            {
                Rect3DManager.instance.disposeRect3d(this._rect3d);
                this._rect3d = null;
                this._img2d = null;
            }
            this._propItem.dispose(param1);
            this._propItem = null;
            this._bg.dispose(param1);
            this._bg = null;
            this._titleTxt.dispose();
            this._titleTxt = null;
            this._levelTxt.dispose();
            this._levelTxt = null;
            this._levelName.dispose();
            this._levelName = null;
            this._combat.dispose();
            this._combat = null;
            this._returnValue.dispose(param1);
            this._returnValue = null;
            this._mountConfig = null;
            super.disposeImpl();
            return;
        }// end function

        override protected function onWindowDownHandler(event:MouseEvent) : void
        {
            return;
        }// end function

        private function mountLevelUpdate(param1:Object) : void
        {
            if (Cache.instance.mount.mountData.mountLevel == 3)
            {
                PlayerSystemAdvanceReturnWin.instance.show();
                PlayerSystemAdvanceReturnWin.instance.addRewardItem(this._propItem.itemData, this._propItem.amount);
            }
            return;
        }// end function

        public function updateInfo() : void
        {
            var _loc_2:Array = null;
            var _loc_3:Array = null;
            var _loc_4:String = null;
            var _loc_1:Number = 0;
            this._mountConfig = MountConfig.instance.getMountInfoByCode(3);
            if (this._mountConfig)
            {
                this._levelName.text = this._mountConfig.name;
                _loc_2 = [];
                _loc_3 = AttributeUtil.attrs.concat();
                _loc_3.splice(2, 1);
                _loc_3.splice(-1);
                for each (_loc_4 in _loc_3)
                {
                    
                    _loc_1 = _loc_1 + CombatUtil.getCombatValueByName(_loc_4, this._mountConfig[_loc_4]);
                }
            }
            this._combat.text = int(_loc_1) + "";
            this._propItem.itemData = new ItemData(int(this._mountConfig.returnAdvanceNum.split("#")[0]));
            this._propItem.amount = this._mountConfig.returnAdvanceNum.split("#")[1];
            this._returnValue.text = Language.getStringByParam(35445, this._mountConfig.returnAdvanceNum.split("#")[1]);
            this._bg.imgUrl = ImagesConst.ActivityBg2_Mount;
            return;
        }// end function

        private function add2D() : void
        {
            if (this.isDisposed)
            {
                return;
            }
            this.visible = true;
            this._rect3d = Rect3DManager.instance.registerWindow(true, new Rectangle(8, 35 - 5, 335, 469), this);
            Rect3DManager.instance.windowShowHander(null, this);
            if (this._img2d == null)
            {
                this._img2d = new Img2D(null, this._bg.bitmapData, new Rectangle(0, 0, 335, 469), false);
            }
            this._rect3d.addImg(this._img2d);
            this.add3d(this._mountConfig);
            return;
        }// end function

        protected function add3d(param1:TMountConfig) : void
        {
            var _loc_2:* = ModelConfig.instance.getInfoByCode(param1.modelId);
            var _loc_3:* = _loc_2.mesh1 + ".md5mesh";
            var _loc_4:* = _loc_2.bone1 + ".skeleton";
            if (this._bodyPlayer == null)
            {
                this._bodyPlayer = FrObjectPool.getObject(ActionPlayer, this);
            }
            this._bodyPlayer.load(_loc_3, _loc_4, _loc_2.texture1);
            this._bodyPlayer.changeAction(ActionName.MountStand);
            this._bodyPlayer.play();
            this._bodyPlayer.scaleValue = 1;
            this._bodyPlayer.rotationY = 50;
            this._bodyPlayer.alpha = 1;
            this._rect3d.addObject3d(this._bodyPlayer, 73 + 72 + 14, 133 + 223 - 60);
            return;
        }// end function

        private function onTakeHandler(event:MouseEvent) : void
        {
            GameProxy.mount.getAdvanceReward(3);
            return;
        }// end function

        override protected function addCloseButton() : void
        {
            return;
        }// end function

        public static function get instance() : MountAvtivityWin
        {
            if (_instance == null)
            {
                _instance = new MountAvtivityWin;
            }
            return _instance;
        }// end function

        public static function isViewShow() : Boolean
        {
            return _instance != null && !_instance.isHide;
        }// end function

    }
}
